package com.elm.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.elm.model.SellerOrder;
import com.elm.model.User;
import com.elm.model.UserOrder;
import com.elm.service.SellerOrderService;
/**
 * 
 * @author pgm
 *
 */
import com.elm.service.UserOrderService;
import com.elm.serviceimpl.SellerOrderServiceImp;
import com.elm.serviceimpl.UserOrderServiceImpl;
public class RemoveOrderController extends HttpServlet{
	UserOrderService uorderservice = new UserOrderServiceImpl();
	SellerOrderService sorderservice = new SellerOrderServiceImp();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf8");
		HttpSession session = req.getSession();
		User user = (User) session.getAttribute("currentUser");
		List<UserOrder> uorders = new ArrayList<UserOrder>();
		int orderindex = Integer.parseInt(req.getParameter("index"));
		uorders = (List<UserOrder>) session.getAttribute("currentorders");
		int uorderid = uorders.get(orderindex).getUserorderid();
//		uorderservice.updateUserOrderState(0, uorderid);
		uorderservice.removeUserOrderState(uorderid);
		sorderservice.removeSellerOrderState(uorderid);
	}
	
}
